package com.betterjr.common.mapper;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/** 
 * @ClassName: CustNumericSerializer 
 * @Description: 将数字格式的String去掉多余位数，比如00序列化为Json输出时会转换为0，仅考虑整数。
 * @author makebono
 * @date 2018年4月12日 上午9:51:21 
 *  
 */
public class CustNumericSerializer extends JsonSerializer<String> {
    @Override
    public void serialize(final String anValue, final JsonGenerator anGen, final SerializerProvider anSerializers)
            throws IOException, JsonProcessingException {
        if (anValue == null) {
            anGen.writeString(" ");
        } else {
            final Number temp = Long.valueOf(anValue);
            anGen.writeString(temp.toString());
        }
    }
}
